using System;
using UnityEngine;
using QFramework;
using Unity.VisualScripting;
using UnityEngine.SceneManagement;

namespace QFramework.Monk
{
	public partial class GameUIController : ViewController,IController
	{
		private void Awake()
		{
			//设置60帧
			Application.targetFrameRate = 60;
		}

		void Start()
		{
			// Code Here
			var waveSystem = this.GetSystem<WaveSystem>();

			//初始化数据
			//AppStart.RestData();
			//初始化波次
			//waveSystem.InitWaveQueue();
			//SceneManager.LoadScene("GameScene");
			//初始化ui
			UIKit.OpenPanel <UIGameStart>();
			UIKit.ClosePanel<UIGamePass>();
			UIKit.ClosePanel<UIGameOver>();
			UIKit.ClosePanel<UINormal>();
			
			AppStart.ChangeGameState(GameState.GameStart);
			
			AppStart.gameState.Register((state) =>
			{
				switch (state)
				{
					case  GameState.GameStart:
						Time.timeScale = 1;
						SceneManager.LoadScene("GameScene");
						//初始化数据
						AppStart.RestData();
						//初始化ui
						UIKit.OpenPanel <UIGameStart>();
						UIKit.ClosePanel<UIGamePass>();
						UIKit.ClosePanel<UIGameOver>();
						UIKit.ClosePanel<UINormal>();
						break;
					case GameState.GamePlaying:
						//初始化能力
						Player.Default.InitAbility();
						//初始化波次
						waveSystem.InitWaveQueue();
						UIKit.OpenPanel<UINormal>();
						break;
					case GameState.GamePass:
						UIKit.OpenPanel<UIGamePass>();
						Time.timeScale = 0;
						break;
					case GameState.GameOver:
						UIKit.OpenPanel<UIGameOver>();
						//Time.timeScale = 0;
						break;
				}
				
			}).UnRegisterWhenGameObjectDestroyed(gameObject);
			

		}

		public IArchitecture GetArchitecture()
		{
			return AppStart.Interface;
		}
	}
}
